<%@ page import="java.sql.ResultSet" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/common/config.jsp" %>
<html>
<head>
    <title>查看详情</title>
</head>
<body>
<%

    String id = "";
    String sql = "SELECT MAX(id)+1 as sno from t_user";
    ResultSet rs = stmt.executeQuery(sql);
    if (rs.next()) {
        id = rs.getString("sno");
    }
    conn.close();
%>


<center>
    <h1>添加学生</h1>
    <h3><span id="error" style="color: red">${msg}</span></h3>
    <form action="save.jsp" method="post" onsubmit="return check();">
        <table border="1px" width="400px">
            <tr>
                <td width="10px">学号：</td>
                <td>
                    <input type="text" name="id" style="width: 100%;" value="<%=id%>" readonly>
                </td>
            </tr>
            <tr>
                <td>姓名：</td>
                <td>
                    <input type="text" name="name" id="name" style="width: 100%;height: 100%">
                </td>
            </tr>
            <tr>
                <td>电话：</td>
                <td>
                    <input type="text" name="phone" id="phone" style="width: 100%;">
                </td>
            </tr>
            <tr>
                <td>密码：</td>
                <td>
                    <input type="password" name="password" id="password" style="width: 100%;">
                </td>
            </tr>
            <tr>
                <td>确认密码：</td>
                <td>
                    <input type="password" name="password2" id="password2" style="width: 100%;">
                </td>
            </tr>
            <tr>
                <td>班级：</td>
                <td>
                    <select name="clazz" style="width: 100%">
                        <option value="18电子商务技术1班">18电子商务技术1班</option>
                        <option value="18电子商务技术2班">18电子商务技术2班</option>
                        <option value="18计算机应用技术（数据应用）">18计算机应用技术（数据应用）</option>
                        <option value="其他">其他</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>根路径：</td>
                <td>
                    <input type="text" name="homePath" id="homePath" style="width: 100%">
                </td>
            </tr>

            <tr>
                <td colspan="2" align="center">
                    <input type="submit" value="保存">
                </td>
            </tr>
        </table>
    </form>
</center>

<script type="application/javascript">
    function check() {
        var error = document.getElementById("error");
        error.innerText = "";
        var name = document.getElementById("name").value;
        var patternName = /^[\u4e00-\u9fa5]{2,4}$/;
        if (!patternName.test(name)) {
            error.innerText = "请输入正确的中文姓名，2-4位汉字";
            return false;
        }

        var phone = document.getElementById("phone").value;
        var patternPhone = /^(13[0-9]|14[5|7]|15[0-9]|18[0|1|2|3|5|6|7|8|9]|177|166)\d{8}$/;
        if (!patternPhone.test(phone)) {
            error.innerText = "请输入正确中国大陆手机号码";
            return false;
        }
        var password = document.getElementById("password").value;
        var patternPassword = /^[0-9A-Za-z]{6,12}$/;
        if (!patternPassword.test(password)) {
            error.innerText = "密码是由数字大写字母，小写字母组成，长度为6-12位";
            return false;
        }
        var password2 = document.getElementById("password2").value;
        if (password != password2) {
            error.innerText = "两次密码不一致";
            return false;
        }
        return true;
    }

</script>


</body>
</html>
